package com.emotionalEnvelope.edu.controller;

import com.emotionalEnvelope.edu.core.RestResponse;
import com.emotionalEnvelope.edu.dto.UserLoginDto;
import com.emotionalEnvelope.edu.param.UserCodeLoginParam;
import com.emotionalEnvelope.edu.param.UserLoginParam;
import com.emotionalEnvelope.edu.param.UserRegisterParam;
import com.emotionalEnvelope.edu.service.impl.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description
 * @Author lqq
 * @Date 2023/7/30
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;


    @PostMapping("/login")
    public RestResponse<UserLoginDto> login(@Validated @RequestBody UserLoginParam user) {
        return userService.login(user);
    }

    @PostMapping("/register")
    public RestResponse<String> signin(@Validated @RequestBody UserRegisterParam user) {
        return userService.register(user);
    }

    /**
     * 发生验证码
     *
     * @param email
     * @return
     */
    @GetMapping("/code")
    public RestResponse<String> code(@Validated @RequestParam String email) {
        return userService.code(email);
    }

    /**
     * 验证码登录
     *
     * @return
     */
    @PostMapping("/loginCode")
    public RestResponse<String> loginCode(@Validated @RequestBody UserCodeLoginParam param) {
        return userService.loginByCode(param);
    }
}
